﻿using System.Collections.Generic;
using System.Linq;
using RefactorThis.EFExtensions;

namespace Qask.Data.Core
{
    public class PostRepository : IPostRepository
    {
        public IList<Post> GetPosts(Specification<Post> specification)
        {
            using (var context = new QaskEntities())
            {
                return specification.SatisfyingEntitiesFrom(context.Posts).ToList();
            }
        }

        public Post CreatePost(Post post)
        {
            using (var context = new QaskEntities())
            {
                context.Posts.Add(post);
                context.SaveChanges();
                return post;
            }
        }

        public Post UpdatePost(Post post)
        {
            using (var context = new QaskEntities())
            {
                context.UpdateGraph(post);
                context.SaveChanges();
                return post;
            }
        }
    }
}
